#ifndef _ERRORFLAG_H_
#define _ERRORFLAG_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
/* Public typedef ------------------------------------------------------------*/

struct ThresholdException
{
    uint32_t time;
};

struct ErrorFlag
{
    uint32_t flag;
    uint32_t __flagCache;
    
	struct ErrorFlagEvent
	{
		void (*trigger)(struct ErrorFlag *error, uint16_t index, void *param);
    	void (*clear)(struct ErrorFlag *error, uint16_t index, void *param);
	}event;

    
};
/* Public define -------------------------------------------------------------*/
/* Public macro --------------------------------------------------------------*/
#define ERRORFLAG_INDEX2FLAG(index)                 (1<<index) 
#define ERROR_FLAG_DELAY							(1<<0)
    
/* Public variables ----------------------------------------------------------*/
/* Public function prototypes ------------------------------------------------*/
void ErrorFlag_Process(struct ErrorFlag *error, void *param);

void ErrorFlag_Trigger(struct ErrorFlag *error, uint16_t index, void *param);
bool ErrorFlag_IsTriggered(struct ErrorFlag *error, uint16_t index);

void ErrorFlag_Clear(struct ErrorFlag *error, uint16_t index, void *param);
bool ErrorFlag_IsCleared(struct ErrorFlag *error, uint16_t index);

void ErrorCheck_NotInThreshold(struct ThresholdException *overException, 
							  int32_t value, 
							  int32_t thresholdLower,
							  int32_t thresholdUpper,
							  int32_t duration,
							  struct ErrorFlag *error, 
							  int32_t index,
						      uint32_t flag);
void ErrorCheck_OverThreshold(struct ThresholdException *overException, 
							  int32_t value, 
							  int32_t threshold,
							  int32_t duration,
							  struct ErrorFlag *error, 
							  int32_t index,
							  uint32_t flag);
void ErrorCheck_LowerThreshold(struct ThresholdException *lowerException, 
							  int32_t value, 
							  int32_t threshold,
							  int32_t duration,
							  struct ErrorFlag *error, 
							  int32_t index,
						   uint32_t flag);
void ErrorCheck_Stagnation(	uint32_t time, 
							uint32_t duration,
							struct ErrorFlag *error, 
							int32_t index,
						    uint32_t flag);

void ErrorCheck_CountOver(uint32_t counter, 
                          uint32_t threshold,
                          struct ErrorFlag *error, 
                          int32_t index,
						  uint32_t flag);
#endif
